﻿/********************************************************************************
** 作者： Mick
** 邮箱： zheng_jinfan@126.com
** 主页： http://www.zhengjinfan.cn
** 创始时间：2016-2-17
** 描述：
**      [辅助类]三重DES
*********************************************************************************/
namespace BestEasyCMS.Framework.Util
{
    /// <summary>
    ///[辅助类]三重DES
    /// </summary>
    public sealed class TripleDesUtil
    {

        #region 构造实例

        /// <summary>
        /// 私有默认构造函数，禁止用户使用new()创建对象
        /// </summary>
        private TripleDesUtil()
        {
            
        }

        /// <summary>
        /// 构建类的实例对象
        /// </summary>
        public static TripleDesUtil Instance
        {
            get { return new TripleDesUtil(); }
        }

        #endregion 构造实例
        /// <summary>
        /// 密钥
        /// </summary>
        private const string DefaultKey = "iasdfmie*/+-*&#$^&*@dsaf";

        //最大192位加密，24字节
        private static readonly TripleDesService MTripleDes = new TripleDesService(DefaultKey);


        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string Encrypt(string source)
        {
            return MTripleDes.Encrypt(source);
        }

        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string Decrypt(string source)
        {
            return MTripleDes.Decrypt(source);
        }

        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="key"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string Encrypt(string key, string source)
        {
            return new TripleDesService(key).Encrypt(source);
        }

        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="key"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string Decrypt(string key, string source)
        {
            return new TripleDesService(key).Decrypt(source);
        }
    }
}